import { requestClient } from '#/api/request';

// 维保记录类型定义
export interface MaintenanceRecord {
  request_id: number;
  vehicle_id: number;
  driver_id: number;
  license_plate: string;
  driver_name: string;
  request_type: string;
  description: string;
  approval_status: string;
  cost: number;
  apply_time: string;
}

// 分页响应类型
export interface PageResponse<T> {
  code: number;
  data: {
    items: T[];
    total: number;
  };
}

// 导出响应类型
export interface ExportResponse {
  code: number;
  data: {
    downloadUrl: string;
    fileName: string;
  };
}

// 查询参数类型
export interface MaintenanceQueryParams {
  licensePlate?: string;
  driverName?: string;
  requestType?: string;
  approvalStatus?: string;
  startDate?: string;
  endDate?: string;
  page: number;
  pageSize: number;
  sortBy?: string;
  sortOrder?: string;
}

// 获取历史维保记录
export async function getMaintenanceHistoryApi(params: MaintenanceQueryParams) {
  return requestClient.get<PageResponse<MaintenanceRecord>>(
    '/maintenance/history',
    {
      params,
    },
  );
}

// 导出维保记录
export async function exportMaintenanceHistoryApi(
  params: MaintenanceQueryParams,
) {
  return requestClient.post<ExportResponse>('/maintenance/history', {
    action: 'export',
    ...params,
  });
}
